home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / strategy / xpat2-1.000 / xpat2-1 / xpat2-1.04 / src / r_Spider.c < prev    next >
C/C++ Source or Header  |  1994-09-28  |  4KB  |  130 lines

  1. /*****************************************************************************/
  2. /*                                         */
  3. /*                                         */
  4. /*    X patience version 2 -- module r_Spider.c                 */
  5. /*                                         */
  6. /*    Characteristics of the ``Spider'' rules                     */
  7. /*    written by Heiko Eissfeldt and Michael Bischoff                 */
  8. /*    see COPYRIGHT.xpat2 for Copyright details                 */
  9. /*                                         */
  10. /*                                         */
  11. /*****************************************************************************/
  12. #include "xpatgame.h"
  13.  
  14. /* calculate score according to Spider documentation */
  15. static int Spider_score(void) {
  16.     Pileindex i;
  17.     Cardindex j;
  18.     int score;
  19.     int total_visible;
  20.     int resolved_suits_in_slots=0;
  21.     int resolved_suits_in_stacks=0;
  22.  
  23.     /* set score to the maximum of facedown cards turned */
  24.     score = ((rules.numcards % rules.numslots) + 
  25.           rules.numslots * rules.facedown) * 10;
  26.  
  27.     for (i = FIRST_SLOT; i <= LAST_SLOT; i++) {
  28.     total_visible = 1;
  29.     for (j = game.ind[i]; j < INDEX_OF_LAST_CARD(i); j++) {
  30.         if (game.visible[j] &&
  31.         in_strong_sequence(game.cards[j], game.cards[j+1])) {
  32.         /* visible combined cards give 2 Points */
  33.         score += 2;
  34.         }
  35.         if (!game.visible[j]) {
  36.         /* each of the unvisible cards at start got 10 Points at first.
  37.            Now clear the points for each yet invisible card. */
  38.         score -= 10;
  39.         total_visible = 0;     /* something is hidden in this slot */
  40.         }
  41.     }
  42.     /* 15 points for each fully visible slot */
  43.     score += total_visible * 15;
  44.  
  45.     /* check for completed suits (even if stacked on each other) */
  46.     if (!EMPTY(i)) {
  47.         /* each full sequence gets 50 points total 
  48.            (12 * 2 points are already there) so add 26 points. */
  49.         Cardindex k;
  50.         for (k = INDEX_OF_LAST_CARD(i); k >= game.ind[i] + 12; --k) {
  51.         if (game.visible[k-12] && complete_suit(i, k) != -1) {
  52.             score += 26;
  53.             ++resolved_suits_in_slots;
  54.         }
  55.         }
  56.     }
  57.     }
  58.     /* check the stacks for complete sequences */
  59.     for (i = 0; i < rules.numstacks; ++i)
  60.     if (!EMPTY(STACK(i))) {
  61.         score += 50;    /* each completed sequence got 50 points */
  62.         resolved_suits_in_stacks ++;
  63.     }
  64.  
  65.     if ((resolved_suits_in_slots + resolved_suits_in_stacks) / 4 /*suits*/ == 
  66.     rules.numdecks) {
  67.     resolved_suits_in_slots -= 3;
  68.     if (resolved_suits_in_slots > 0) 
  69.         score += resolved_suits_in_slots * 2;
  70.     }
  71.     return score;
  72. }
  73.  
  74. static void Spider_init(void) {
  75.     switch (rules.param[0]) {
  76.     case 0:
  77.     rules.move_bits |= DC_NOEMPTY;        /* std. Spider rules */
  78.     break;
  79.     case 1:
  80.     rules.move_bits |= DC_STRONGOK;        /* Heiko's variant */
  81.     break;
  82.     case 2:
  83.     rules.move_bits |= DC_RELAXEDOK;    /* Heiko's variant */
  84.     break;
  85.     default:
  86.     fprintf(stderr, "Spider: option to -relaxed may be 0, 1, or 2. Found %d\n", rules.param[0]);
  87.     exit(1);
  88.     }
  89. }
  90.  
  91.  
  92. struct rules Spider_rules = {
  93.     "Spider",    /* shortname */
  94.     NULL,    /* longname */
  95.     NULL,       /* abbrev */
  96.     0,        /* layout_hints */
  97.     0,        /* variant */
  98.     CUSTOM_STD|CUSTOM_PARAM0,    /* customizable */
  99.     0,        /* customized */
  100.     104,    /* numcards */
  101.     8,        /* numstacks */
  102.     10,        /* numslots */
  103.     0,        /* numtmps */
  104.     2,        /* numdecks */
  105.     13,        /* cards_per_color */
  106.     0,        /* numjokers */
  107.     {0, 0, 0, 0},/* param[0], param[1], param[2], param[3] */
  108.     4,        /* facedown */
  109.     1,        /* faceup */
  110.     0,        /* newgame_bits */
  111.     NULL,    /* new_game */
  112.     NULL,    /* game_won */
  113.     NULL,    /* new_cards */
  114.     ES_ALL|US_R|MG_RS|ST_13, /* move_bits */
  115.     NULL,    /* deal_cards */
  116.     NULL,    /* undeal_cards */
  117.     NULL,    /* stackable */
  118.     NULL,    /* movevalid */
  119.     NULL,    /* valid */
  120.     NULL,    /* relaxed_valid */
  121.     std_good_hint,    /* good_hint */
  122.     NULL,    /* automove */
  123.     Spider_score,/* score */
  124.     1000,    /* maxscore */
  125.     {0, 0, 0, 0}, /* paramstring blocks */
  126.     0,        /* used */
  127.     Spider_init,    /* initfunc */
  128.     NULL,    /* local keyboard bindings */
  129. };
  130.